package com.springboot.springautowired.aspectStudy.baseOfAnnotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author mac
 * @date 2021/9/18 3:22 下午
 */
@Component
@Aspect
public class BaseAnnotationAspect {
    /**
     * 获取标记了该注解的切入点
     */
    @Pointcut("@annotation(com.springboot.springautowired.aspectStudy.baseOfAnnotation.AspectAnno)")
    public void qierudian(){}

    /**
     * 如果是标记了该注解的方法会触发环绕通知
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("qierudian()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{
        /**
         *         Object result = null;
         *         Signature signature = joinPoint.getSignature();
         *         MethodSignature methodSignature = (MethodSignature) signature;
         *         Method method = methodSignature.getMethod();
         *         //判断当前注解是否在当前方法上头，是返回true，不是返回false
         *         if (method.isAnnotationPresent(ValidateSign.class)) {
         *             OutterParam arg1 = null;
         *             Object[] args = joinPoint.getArgs();
         *             for (Object arg : args) {
         *                 arg1 = (OutterParam) arg;
         *             }
         *             if (validateSign(arg1)) {
         *                 result = joinPoint.proceed();
         *                 return result;
         *             }
         *         }
         *         return joinPoint.proceed();
         */
        return null;
    }
}
